﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Extract email addresses</title>
    <link href="Styles/js-console.css" rel="stylesheet" />
    <script src="Scripts/isValidInput.js"></script>
</head>
<body>
    <div id="task">
        <p>
            Write a function for extracting all email addresses from given text. All substrings that match the format &lt;identifier&gt;@&lt;host&gt;…&lt;domain&gt; should be recognized as emails. Return the emails as array of strings.
        </p>
        <a href="8.html">Previous task</a>
        <a href="10.html">Next task</a>
    </div>

    <br />
    <button onclick="extractEmailAddresses()">Run script</button>

    <div id="js-console"></div>
    <script src="Scripts/js-console.js"></script>

    <script>
        function extractEmailAddresses() {
            var text = "mail@gmail.com.uk.co.uk Write a program -mail_invalid#valid@gmail.com for extracting mail-91_abc@uk.co.com some_mail@gmail.com all email addresses form@a.given.text All substrings@mail.co.uk.net and one last email svetlin@nakov.com";
            var emailAddresses = text.match(/[a-zA-Z][\w-\.]+@[a-zA-Z][a-zA-Z-]+\.([a-zA-Z][a-zA-Z-]+\.){0,200}[a-zA-Z]{2,4}/g);
            for (var i = 0; i < emailAddresses.length; i++) {
                jsConsole.writeLine(emailAddresses[i]);
            }
        }
    </script>
</body>
</html>
